﻿using BW.EatRabbit.API.Application.Commands;
using BW.EatRabbit.Domain;
using BW.EatRabbit.ErrorCode;
using BW.EatRabbit.Infrastructure.Interfaces;
using MediatR;

namespace BW.EatRabbit.API.Application.CommandHandlers
{
    /// <summary>
    /// 创建基本信息命令处理
    /// </summary>
    public class Basic_InformationCreateCommandHandler : IRequestHandler<Basic_InformationCreateCommand, APIResult<int>>
    {
        /// <summary>
        /// 基本信息仓储
        /// </summary>
        private readonly IBaseRepository<BasicInformation> basicinformationRepository;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="basicinformationRepository">基本信息仓储</param>
        public Basic_InformationCreateCommandHandler(IBaseRepository<BasicInformation> basicinformationRepository)
        {
            this.basicinformationRepository = basicinformationRepository;

        }
        public Task<APIResult<int>> Handle(Basic_InformationCreateCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.Code = ResultCode.添加成功;
            result.Message = ResultCode.添加成功.ToString();

            BasicInformation basic = new BasicInformation();
            basic.GoodsId = request.GoodsId;
            basic.ProductionBatch = request.ProductionBatch;
            basic.ShelfLife = request.ShelfLife;
            basic.License=request.License;
            basic.Completeness = request.Completeness;
            basic.Producer=request.Producer;
            basic.CoverImage = request.CoverImage;
            basic.Creator = request.UserNickname;

            basicinformationRepository.AddEntity(basic);


            return Task.FromResult(result);
        }
    }
}
